<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	pageContext.setAttribute("basePath", request.getContextPath());
%>
<!DOCTYPE html>
<html lang="zh">
<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="">
<meta name="description" content="">
<title>备份还原</title>
<link rel="shortcut icon" href="favicon.ico">
<link href="${basePath }/static/css/bootstrap.min.css" rel="stylesheet" />
<link href="${basePath }/static/css/font-awesome.min.css"
	rel="stylesheet" />
<!-- bootstrap-table 表格插件样式 -->
<link
	href="${basePath }/static/ajax/libs/bootstrap-table/bootstrap-table.min.css"
	rel="stylesheet" />
<link href="${basePath }/static/css/animate.css" rel="stylesheet" />
<link href="${basePath }/static/css/style.css" rel="stylesheet" />
<link href="${basePath }/static/ruoyi/css/ry-ui.css" rel="stylesheet" />


<link
	href="${basePath }/static/ajax/libs/jquery-layout/jquery.layout-latest.css"
	rel="stylesheet" />


<link
	href="${basePath }/static/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css"
	rel="stylesheet" />

</head>
<body class="gray-bg">

	<div class="ui-layout-center">
		<div class="container-div">
			<div class="row">
				<div class="col-sm-12 search-collapse">
					<form id="user-form">
						<input type="hidden" id="deptId" name="deptId"> <input
							type="hidden" id="parentId" name="parentId">
						<div class="select-list">
							<ul>
								<li class="select-time"><label>备份时间： </label> <input
									type="text" class="time-input" id="startTime"
									placeholder="开始时间" name="params[beginTime]" /> <span>-</span>
									<input type="text" class="time-input" id="endTime"
									placeholder="结束时间" name="params[endTime]" /></li>
								<li><a class="btn btn-primary btn-rounded btn-sm"
									onclick="$.table.search()"> <i class="fa fa-search"></i>&nbsp;搜索
								</a> <a class="btn btn-warning btn-rounded btn-sm"
									onclick="$.form.reset()"> <i class="fa fa-refresh"></i>&nbsp;重置
								</a></li>
							</ul>
						</div>
					</form>
				</div>


				<div class="col-sm-12 select-table table-striped">
					<div class="bootstrap-table">
						<div class="fixed-table-toolbar">
							<div class="bs-bars pull-left">
								<div class="btn-group-sm" id="toolbar" role="group">
									<a class="btn btn-info" data-toggle="modal"
										data-target="#backup-modal"> <i class="fa fa-upload"></i>
										备份
									</a> <a class="btn btn-danger" onclick=""> <i
										class="fa fa-upload"></i> 删除
									</a>
								</div>
							</div>
						</div>


						<div class="fixed-table-container" style="padding-bottom: 0px;">
							<div class="fixed-table-header" style="display: none;">
								<table></table>
							</div>
							<div class="fixed-table-body">
								<div class="fixed-table-loading"
									style="top: 41px; display: none;">正在努力地加载数据中，请稍候……</div>

								<table id="bootstrap-table" data-mobile-responsive="true"
									class="table table-hover">
									<thead>
										<tr>
											<th>
												<div class="th-inner ">编号</div>
												<div class="fht-cell"></div>
											</th>
											<th>
												<div class="th-inner ">备份内容</div>
												<div class="fht-cell"></div>
											</th>
											<th>
												<div class="th-inner ">备份时间</div>
												<div class="fht-cell"></div>
											</th>
											<th>
												<div class="th-inner ">操作人员ID</div>
												<div class="fht-cell"></div>
											</th>
											<th>
												<div class="th-inner ">文件大小</div>
												<div class="fht-cell"></div>
											</th>
											<th>
												<div class="th-inner ">操作</div>
												<div class="fht-cell"></div>
											</th>
										</tr>
									</thead>

									<!-- <tbody>
										<tr data-index="1">
											<td class="bs-checkbox "><input data-index="0"
												name="btSelectItem" type="checkbox"></td>
											<td>2</td>
											<td>&lt;个人信息&gt;&lt;茶叶信息&gt;&lt;生产记录&gt;</td>
											<td>2019-07-22 09：38：42</td>
											<td>张无忌</td>
											<td>20190002</td>
											<td>30MB</td>

											<td><a class="btn btn-info btn-xs "
												href="javascript:void(0)" onclick=""> <i
													class="fa fa-key"></i>还原
											</a> <a class="btn btn-danger btn-xs " href="javascript:void(0)"
												onclick=""> <i class="fa fa-key"></i>删除
											</a></td>
										</tr>
									</tbody> -->

									<tbody>
										<c:forEach items="${query.list }" var="backupRecord">
											<tr>
												<td>${backupRecord.dataBackupId}</td>
												<td>${backupRecord.backupType}</td>
												<td>${ backupRecord.backupTime}</td>
												<td>${ backupRecord.backupUserid}</td>
												<td>${ backupRecord.backupDataSize}</td>
												<td><a class="btn btn-info btn-xs "
													href="javascript:void(0)" onclick="restore(${backupRecord.dataBackupId})"> <i
														class="fa fa-key"></i>还原
												</a> <a class="btn btn-danger btn-xs " href="javascript:void(0)"
													onclick=""> <i class="fa fa-key"></i>删除
												</a></td>
											</tr>
										</c:forEach>
									</tbody>


								</table>
							</div>

							<div class="fixed-table-pagination" style="display: block;">
								<div class="pull-left pagination-detail">
									<span class="pagination-info">第${query.pageNum }页，共${query.pages
+ 1}页，共
										${query.total } 条记录。</span>
								</div>
								<div class="pull-right pagination">
									<ul class="pagination pagination-outline">
										<c:choose>
											<c:when test="${query.pageNum == 1 }">
												<li class="page-pre active"><a
													href="javascript:void(0)">‹</a></li>
											</c:when>
											<c:otherwise>
												<li class="page-pre"><a
													href="${basePath }/security/backup/list.do?
pagenum=${query.pageNum - 1 }">‹</a>
												</li>
											</c:otherwise>
										</c:choose>
										<c:forEach items="${query.navigateNums }" var="num">
											<c:if test="${query.pageNum == num }">
												<li class="page-number active"><a
													href="javascript:void(0)">${num }</a></li>
											</c:if>
											<c:if test="${query.pageNum != num }">
												<li class="page-number"><a
													href="${basePath }/security/backup/list.do?
pagenum=${num }">${num }</a>
												</li>
											</c:if>
										</c:forEach>
										<c:if test="${query.pageNum == query.pages+1 }">
											<li class="page-next active"><a
												href="javascript:void(0)">›</a></li>
										</c:if>
										<c:if test="${query.pageNum < query.pages }">
											<li class="page-next"><a
												href="${basePath }/security/backup/list.do?
pagenum=${query.pageNum + 1 }">›</a>
											</li>
										</c:if>
									</ul>
								</div>
							</div>
						</div>
					</div>
				</div>



			</div>
			<div class="clearfix"></div>
		</div>


	</div>
	</div>
	</div>

	<!-- 备份模态框开始 -->
	<div class="modal fade" id="backup-modal">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">选择备份数据</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal m-t" id="signupForm" method="post"
						action="">
						<div class="form-group">
							<label> <input type="checkbox" value="productionRecord"
								name="backupName">生产记录
							</label>
						</div>
						<div class="form-group">
							<label> <input type="checkbox" value="exceptionRecord"
								name="backupName">异常记录
							</label>
						</div>
						<div class="form-group">
							<label> <input type="checkbox"
								value="realtimeDataRecording" name="backupName">实时数据记录
							</label>
						</div>
						<div class="form-group">
							<label> <input type="checkbox" value="standardParameters"
								name="backupName">标准参数记录
							</label>
						</div>
						<div class="form-group">
							<label> <input type="checkbox" value="userInfo"
								name="backupName">个人信息
							</label>
						</div>
						<div class="form-group">
							<label> <input type="checkbox" value="basicInfo"
								name="backupName">基础信息
							</label>
						</div>
						<div class="form-group">
							<label> <input type="checkbox" value="InventoryInfo"
								name="backupName">库存信息
							</label>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
					<button type="button" class="btn btn-primary"
						onclick="submitBackup()">Star backup</button>
				</div>
			</div>
		</div>
	</div>
	<!-- 备份模态框结束 -->


	<script src="${basePath }/static/js/jquery.min.js"></script>
	<script src="${basePath }/static/js/bootstrap.min.js"></script>
	<!-- bootstrap-table 表格插件 -->
	<script
		src="${basePath }/static/ajax/libs/bootstrap-table/bootstrap-table.min.js"></script>
	<script
		src="${basePath }/static/ajax/libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
	<script
		src="${basePath }/static/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.js"></script>
	<script
		src="${basePath }/static/ajax/libs/bootstrap-table/extensions/toolbar/bootstrap-table-toolbar.min.js"></script>
	<script
		src="${basePath }/static/ajax/libs/bootstrap-table/extensions/columns/bootstrap-table-fixed-columns.js"></script>
	<!-- jquery-validate 表单验证插件 -->
	<script
		src="${basePath }/static/ajax/libs/validate/jquery.validate.min.js"></script>
	<script src="${basePath }/static/ajax/libs/validate/messages_zh.min.js"></script>
	<script
		src="${basePath }/static/ajax/libs/validate/jquery.validate.extend.js"></script>
	<!-- jquery-validate 表单树插件 -->
	<script
		src="${basePath }/static/ajax/libs/bootstrap-treetable/bootstrap-treetable.js"></script>
	<!-- jquery-export 表格导出插件 -->
	<script
		src="${basePath }/static/ajax/libs/bootstrap-table/extensions/export/bootstrap-table-export.js"></script>
	<script
		src="${basePath }/static/ajax/libs/bootstrap-table/extensions/export/tableExport.js"></script>
	<!-- 遮罩层 -->
	<script src="${basePath }/static/ajax/libs/blockUI/jquery.blockUI.js"></script>
	<script src="${basePath }/static/ajax/libs/iCheck/icheck.min.js"></script>
	<script src="${basePath }/static/ajax/libs/layer/layer.min.js"></script>
	<script src="${basePath }/static/ajax/libs/layui/layui.js"></script>
	<script src="${basePath }/static/ruoyi/js/common.js?v=4.0.0"></script>
	<script src="${basePath }/static/ruoyi/js/ry-ui.js?v=4.0.0"></script>
	<script>
		var ctx = "\/";
	</script>


	<script
		src="${basePath }/static/ajax/libs/jquery-layout/jquery.layout-latest.js"></script>


	<script
		src="${basePath }/static/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js"></script>

</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的用户数据
                &nbsp; <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i
                    class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>

<!-- 重要！！！本界面ajax -->
<script type="text/javascript">
	function getRootPath() {
		let href = window.document.location.href;
		let pathName = window.document.location.pathname;
		let index = href.indexOf(pathName);
		let localhost = href.substring(0, index);
		let project = pathName.substring(0,
				(pathName.substr(1).indexOf('/')) + 1);
		return (localhost + project);
	}
	var rootPath = getRootPath();

	function submitBackup() {
		var obj = document.getElementsByName('backupName');
		//取到对象数组后，我们来循环检测它是不是被选中  
		var backupTableName = '';
		for (var i = 0; i < obj.length; i++) {
			if (obj[i].checked) {
				backupTableName += obj[i].value + ',';
			}
		}

		if (backupTableName != '') {
			$.ajax({
				url : rootPath + "/security/backup.do",
				type : "POST",
				dataType : "json",
				data : {
					backupTableName : backupTableName,
				},
				success : function(response) {
					if (response.RESULT === "failed") {
						$.modal.alert("备份数据库失败");
						$("#response_code").val("");
					} else {
						alert('success');
					}
				}
			});
		} else {
			alert('你还没有选择任何内容！');
		}
	}
	
	function restore(dataBackupId){
		$.ajax({
			url : rootPath + "/security/reduction.do",
			type : "POST",
			dataType : "json",
			data : {
				dataBackupId : dataBackupId,
			},
			success : function(response) {
				if (response.RESULT === "failed") {
					$.modal.alert("数据库还原失败");
					$("#response_code").val("");
				} else {
					alert('success');
				}
			}
		});
	}
	
</script>

</html>